package basic;

/**
 * @Author: 海琳琦
 * @Date: 2021/9/8 15:57
 */
public class Title557 {
    public static void main(String[] args) {
        System.out.println(reverseWords("abc cda"));
    }

    private static String reverseWords(String s) {
        StringBuffer sb = new StringBuffer();
        int i = 0;
        while(i<s.length()){
            int start = i;
            while(i<s.length()&&s.charAt(i)!=' '){
                i++;
            }
            for (int j = start; j <i; j++) {
                sb.append(s.charAt(start+i-1-j));
            }
            while(i<s.length()&&s.charAt(i)==' '){
                i++;
                sb.append(' ');
            }
        }
        return sb.toString();
    }
}
